package com.example.smartall.fragment;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.example.smartall.R;
import com.example.smartall.fragment.base.BaseSplashFragment;
import com.example.smartall.ui.HomeActivity;
import com.example.smartall.diaglog.NetSetDialog;
import com.example.smartall.utils.Constant;
import com.example.smartall.utils.SPUtils;

import java.util.Objects;

/**
 * 第五页引导页
 */

public class SplashLoginFragment extends BaseSplashFragment implements View.OnClickListener{

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private ImageView ivSplash;
    private Button btPort;
    private Button btIn;

    public Button getBtPort() {
        return btPort;
    }

    public SplashLoginFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_splash_login,null);
        ivSplash = (ImageView) view.findViewById(R.id.iv_splash_login);
        ivSplash.setImageResource(img);
        btPort = (Button) view.findViewById(R.id.bt_port);
        btIn = (Button) view.findViewById(R.id.bt_in);

        btIn.setOnClickListener(this);
        btPort.setOnClickListener(this);
        return view;
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_port:
                NetSetDialog dialog = new NetSetDialog(Objects.requireNonNull(getActivity()));
                dialog.show();
                break;
            case R.id.bt_in:
                SPUtils spUtils = SPUtils.config(getActivity(), Constant.SP_NET_FILE_NAME);
                if (spUtils.hasSet()){
                    startActivity(new Intent(getActivity(), HomeActivity.class));
                }else {
                    showToast("请设置端口及ip后再进入软件");
                }
                break;
            default:
                break;
        }
    }
}